package com.example.administrator.myapplication.activity.albumActivity.fragment;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.util.Pair;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.administrator.myapplication.BR;
import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.activity.albumActivity.bean.programEntity.Album;
import com.example.administrator.myapplication.databinding.FragmentContentBinding;
import com.example.administrator.myapplication.until.CommentRecyclerAdapter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * A simple {@link Fragment} subclass.
 */
public class ContentFragment extends Fragment {
   private FragmentContentBinding binding;
    private CommentRecyclerAdapter<Object> adapter;
    private  Album album;

    public ContentFragment() {
        // Required empty public constructor
    }

    public static ContentFragment newInstance(Album album) {
        Bundle args = new Bundle();
        args.putSerializable("album",album);
        ContentFragment fragment = new ContentFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return DataBindingUtil.inflate(inflater,R.layout.fragment_content, container, false).getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding = DataBindingUtil.getBinding(view);
        album = (Album) getArguments().getSerializable("album");
        String title = album.getTitle();
       Toast.makeText(getContext(), title, Toast.LENGTH_SHORT).show();
        aboutRecycler();
    }

    private void aboutRecycler() {
        HashMap<Class<?>,Pair<Integer,Integer>> map = new HashMap<>();
        map.put(null,Pair.create(R.layout.content_fragment_item1, BR.contnetFragmentAlbum));
        adapter = new CommentRecyclerAdapter<>(getContext(),new ArrayList<>(),map);
        binding.recycler.setAdapter(adapter);
        adapter.add(album);
    }
}
